package com.mall.web.controller.admin;

import com.mall.common.config.Global;
import com.mall.common.core.controller.BaseController;
import com.mall.framework.util.ShiroUtils;
import com.mall.system.domain.entity.SysMenu;
import com.mall.system.domain.entity.SysUser;
import com.mall.system.service.SysConfigService;
import com.mall.system.service.SysMenuService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * 首页 业务处理
 * <p>
 * Created by zhonglin on 2020/4/8.
 */
@Controller
public class SysIndexController
    extends BaseController {

  @Autowired
  private SysMenuService menuService;

//  @Autowired
//  private ISysConfigService configService;

  @Autowired
  private SysConfigService configService;

  // 系统首页
  @GetMapping("/admin/index")
  public String index(ModelMap mmap) {
    // 取身份信息
    SysUser user = ShiroUtils.getSysUser();
    // 根据用户id取出菜单
    List<SysMenu> menus = menuService.selectMenusByUser(user);
    mmap.put("menus", menus);
    mmap.put("user", user);
    mmap.put("sideTheme", configService.selectConfigByKey("sys.index.sideTheme"));
    mmap.put("skinName", configService.selectConfigByKey("sys.index.skinName"));
    mmap.put("copyrightYear", Global.getCopyrightYear());
    return "admin/index";
  }

  // 切换主题
  @GetMapping("/system/switchSkin")
  public String switchSkin(ModelMap mmap) {

    return "skin";
  }

  // 系统介绍
  @GetMapping("/system/main")
  public String main(ModelMap mmap) {

    mmap.put("version", Global.getVersion());
    return "admin/main";
  }

}
